﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数组找出数组最大跟最小值
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = { -1, -2, 3, 4, 5, 6, 7, 8, 99999 };
            int max=0, min=0;
            Test1(num, out max, out min);
            Console.WriteLine("Test1    数组最大值{0} 数组最小值{1}", max,min);
            Console.WriteLine("Test2    数组最大值{0} 数组最小值{1}", max, min);
            Console.ReadKey();

        }
        static void Test1(int[] num,out int max,out int min)
        {
            max = int.MinValue;//确保数组里的元素值肯定会比他小.
            min = int.MaxValue;//确保数组里元素值肯定会比他大
            for (int i = 0; i < num.Length; i++)
            {
                if (num[i]>max)
                {
                    max = num[i];
                }
                if (num[i]<min)
                {
                    min = num[i];
                }
            }
        }

        static void Test2(int[] num,out int max,out int min)
        {
            max=num[0];
            min=num[1];
            for (int i = 0; i < num.Length; i++)
            {
                if (num[i]>max)
                {
                    max = num[i];
                }
                if (num[i]<min)
                {
                    min = num[i];
                }
            }

        }
    }
}
